100 REM ------------------------------------------------------------
110 REM SPLIT.BAS
120 REM WRITTEN BY GARY PEEK
130 REM LAST UPDATE 4/30/02
140 REM ------------------------------------------------------------
150 T=TIMER
160 IF TIMER<T+.5 THEN 160
170 CLS
180 PRINT "SPLIT - Split a large file into smaller ones"
190 PRINT "that will fit on 1.44 megabyte diskettes"
200 PRINT:PRINT "S = Split a file"
210 PRINT "J = Join files split with this program"
220 SJ$=INKEY$:IF SJ$="" THEN 220
230 IF SJ$=CHR$(27) OR SJ$=CHR$(13) THEN END
240 IF SJ$="s" THEN SJ$="S"
250 IF SJ$="j" THEN SJ$="J"
260 IF SJ$="S" THEN 500
270 IF SJ$="J" THEN 2000
280 GOTO 180
290 REM ------------------------------------------------------------
500 CLS
510 PRINT "Enter name of file to split including extension: ";
520 LINE INPUT FINEXT$
530 IF FINEXT$="" THEN 150
540 ON ERROR GOTO 700
550 OPEN FINEXT$ FOR INPUT AS #1
560 CLOSE #1
570 ON ERROR GOTO 0
580 OPEN "R",#1,FINEXT$,1
590 FIELD #1,1 AS FINBYTE$
600 FINLEN=LOF(1)
610 FINNUM=1
620 IF FINLEN>1440000 THEN 800
630 CLOSE #1
640 PRINT FINEXT$+" is less than 1.44 megabytes, no need to split"
650 T=TIMER
660 IF TIMER<T+2 THEN 660
670 GOTO 150
680 REM ---------------
700 RESUME 710
710 ON ERROR GOTO 0
720 PRINT FINEXT$+" not found"
730 T=TIMER
740 IF TIMER<T+2 THEN 740
750 GOTO 150
760 REM ---------------
800 I=INSTR(FINEXT$,".")
810 IF I=0 THEN FIN$=FINEXT$:GOTO 830
820 FIN$=LEFT$(FINEXT$,LEN(FINEXT$)-I+1)
830 NUMFILE=FINLEN/1440000
840 NUMFILE=INT(NUMFILE+2)
850 PRINT "Number of files to create ="+STR$(NUMFILE)
860 PRINT "Saving file information in "+FIN$+".001"
870 OPEN FIN$+".001" FOR OUTPUT AS #2
880 PRINT #2, FINEXT$
900 PRINT #2, NUMFILE
910 CLOSE #2
920 REM ---------------
1000 DISK=2
1010 REM ---
1020 FOUTNUM=1
1030  EXT$=STR$(DISK)
1040  EXT$=RIGHT$(EXT$,LEN(EXT$)-1)
1050  EXT$="000"+EXT$
1060  EXT$=RIGHT$(EXT$,3)
1070  PRINT "Creating "+FIN$+"."+EXT$+" starting at "+TIME$
1080  OPEN FIN$+"."+EXT$ FOR OUTPUT AS #2
1090  REM ---
1100  IF FINNUM>FINLEN THEN 1200
1110   IF INKEY$=CHR$(27) THEN 1250
1115   GET #1,FINNUM
1120   PRINT #2, FINBYTE$;
1130   IF FOUTNUM=1440000 THEN CLOSE #2:DISK=DISK+1:GOTO 1020
1140   FINNUM=FINNUM+1
1150   FOUTNUM=FOUTNUM+1
1160 GOTO 1100
1170 REM -----
1200 CLOSE #1:CLOSE #2
1210 PRINT "Finished"
1220 T=TIMER
1230 IF TIMER<T+2 THEN 1230
1240 GOTO 150
1250 CLOSE #1:CLOSE #2
1260 PRINT "!!! Aborted !!!"
1270 GOTO 1220
1990 REM -------------------------------------------------------------
2000 CLS
2010 PRINT "Enter name of files to join (.00x extensions assumed): ";
2020 LINE INPUT FORG$
2030 IF FORG$="" THEN 150
2040 FORGEXT$=FORG$+".001"
2050 ON ERROR GOTO 2200
2060 OPEN FORGEXT$ FOR INPUT AS #1
2070 CLOSE #1
2080 PRINT "Information file "+FORGEXT$+" found"
2090 ON ERROR GOTO 0
2100 OPEN FORGEXT$ FOR INPUT AS #1
2110 INPUT #1,FOUTEXT$
2120 INPUT #1,NUMFILE
2130 CLOSE #1
2140 PRINT "Original file name = "+FOUTEXT$
2150 PRINT "Number of files created ="+STR$(NUMFILE)
2160 GOTO 2400
2170 REM -----
2200 RESUME 2210
2210 ON ERROR GOTO 0
2220 PRINT "Information file "+FORGEXT$+" not found"
2230 PRINT "Enter original file name including extension: ";
2240 LINE INPUT FOUTEXT$
2250 IF FOUTEXT$="" THEN 150
2260 PRINT "Enter number of files created when original file was split,"
2270 PRINT "(including the information file "+FORGEXT$+"): ";
2280 LINE INPUT NUMFILE$
2290 IF NUMFILE$="" THEN 150
2300 NUMFILE=VAL(NUMFILE$)
2310 REM -----
2400 I=INSTR(FOUTEXT$,".")
2410 IF I=0 THEN FIN$=FOUTEXT$:GOTO 830
2420 FIN$=LEFT$(FOUTEXT$,LEN(FOUTEXT$)-I+1)
2430 FOR DISK=2 TO NUMFILE
2440  EXT$=STR$(DISK)
2450  EXT$=RIGHT$(EXT$,LEN(EXT$)-1)
2460  EXT$="000"+EXT$
2470  EXT$=RIGHT$(EXT$,3)
2480  ON ERROR GOTO 2600
2490  OPEN FIN$+"."+EXT$ FOR INPUT AS #1
2500  CLOSE #1
2510 NEXT DISK
2520 GOTO 2700
2530 REM -----
2600 RESUME 2610
2610 ON ERROR GOTO 0
2620 PRINT FIN$+"."+EXT$+" required but not found"
2630 T=TIMER
2640 IF TIMER<T+2 THEN 2640
2650 GOTO 150
2660 REM -----
2700 OPEN FOUTEXT$ FOR OUTPUT AS #2
2710 FOR DISK=2 TO NUMFILE
2720  EXT$=STR$(DISK)
2730  EXT$=RIGHT$(EXT$,LEN(EXT$)-1)
2740  EXT$="000"+EXT$
2750  EXT$=RIGHT$(EXT$,3)
2760  OPEN "R",#1,FIN$+"."+EXT$,1
2770  FIELD #1,1 AS FINBYTE$
2780  FINLEN=LOF(1)
2790  FINNUM=1
2800  PRINT "Reading data from "+FIN$+"."+EXT$+" starting at "+TIME$
2810 REM -----
2900  IF INKEY$=CHR$(27) THEN 1250
2905  GET #1,FINNUM
2910  PRINT #2, FINBYTE$;
2920  IF FINNUM<FINLEN THEN FINNUM=FINNUM+1:GOTO 2900
2930  CLOSE #1
2940 NEXT DISK
2950 CLOSE #2
2960 PRINT "Finished"
2970 T=TIMER
2980 IF TIMER<T+2 THEN 2980
2990 GOTO 150
3000 CLOSE #1:CLOSE #2
3010 PRINT "!!! Aborted !!!"
3020 GOTO 2970
